package org.jix.weblog.module.common.domain.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jix.weblog.module.common.domain.dos.UserDO;

import java.time.LocalDateTime;

/**
 * @version 1.0
 * @Author Jix
 * @Date 2024/7/21 15:35
 * @注释
 */


public interface UserMapper extends BaseMapper<UserDO> {
    default UserDO selectByUsername(String username) {
        LambdaQueryWrapper<UserDO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserDO::getUsername, username);
        return selectOne(wrapper);
    }
    default int updatePasswordByUsername(String username, String password) {
        LambdaUpdateWrapper<UserDO> wrapper = new LambdaUpdateWrapper<>();
        //设置更新字段
        wrapper.set(UserDO::getPassword, password);
        wrapper.set(UserDO::getUpdateTime, LocalDateTime.now());
        //更新条件
        wrapper.eq(UserDO::getUsername, username);
        return update(null, wrapper);
    }
}
